import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  SetMetadata,
  Query,
  DefaultValuePipe,
  ParseIntPipe
} from '@nestjs/common';
import { AdventureService } from './adventure.service';
import { CreateAdventureDto } from './dto/create-adventure.dto';
import { UpdateAdventureDto } from './dto/update-adventure.dto';
import { ApiOperation, ApiQuery, ApiResponse, ApiTags } from '@nestjs/swagger';
import { ReflectMetadataKeys } from '@/common/enum/ReflectMetadataKeys';
import { Adventure } from './entities/adventure.entity';
import { adventureQueryVo } from '@/common/interface';

@ApiTags('工会管理')
@Controller('adventure')
export class AdventureController {
  constructor(private readonly adventureService: AdventureService) {}

  @ApiOperation({ summary: '工会创建' })
  @SetMetadata(ReflectMetadataKeys.ACTION_NAME, '工会创建')
  @Post()
  create(@Body() createAdventureDto: CreateAdventureDto) {
    return this.adventureService.create(createAdventureDto);
  }

  @ApiOperation({ summary: '工会列表' })
  @ApiResponse({ status: 200, description: '200', type: [Adventure] })
  @ApiQuery({
    name: 'name',
    required: false,
    description: '工会名称',
    type: String,
  })
  @ApiQuery({
    name: 'queryDate',
    required: false,
    description: '查询时间',
    type: Array
  })
  @ApiQuery({
    name: 'page',
    required: false,
    description: '第几页',
    type: Number,
    example: 1
  })
  @ApiQuery({
    name: 'limit',
    required: false,
    description: '每页显示数',
    type: Number,
    example: 10
  })
  @SetMetadata(ReflectMetadataKeys.ACTION_NAME, '工会列表')
  @Get()
  findAll(
    @Query() query: adventureQueryVo,
    @Query('page', new DefaultValuePipe(1), ParseIntPipe) page = 1,
    @Query('limit', new DefaultValuePipe(10), ParseIntPipe) limit = 10
  ) {
    return this.adventureService.findAll({ page, limit }, query);
  }

  @ApiOperation({ summary: '工会详情' })
  @ApiResponse({ status: 200, description: 'success', type: Adventure })
  @SetMetadata(ReflectMetadataKeys.ACTION_NAME, '工会详情')
  @Get(':id')
  findOne(@Param('id', ParseIntPipe) id: number) {
    return this.adventureService.findOne(id);
  }

  @ApiOperation({ summary: '修改工会' })
  @SetMetadata(ReflectMetadataKeys.ACTION_NAME, '修改工会')
  @Patch()
  update(@Body() updateAdventureDto: UpdateAdventureDto) {
    return this.adventureService.update(updateAdventureDto);
  }

  @ApiOperation({ summary: '删除工会' })
  @SetMetadata(ReflectMetadataKeys.ACTION_NAME, '删除工会')
  @Delete(':id')
  remove(@Param('id', ParseIntPipe) id: number) {
    return this.adventureService.remove(id);
  }
}
